package struts.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import struts.form.ActionForm;

/**
 * ActionForm辅助类
 * 
 * @author zhouhong
 * @date 2014-9-21 新建
 */
public class FormHelper {
	public static ActionForm createForm(HttpServletRequest req, String formClass)
	{
		ActionForm form = null;
		try{
			Class clazz = Class.forName(formClass);
			form = (ActionForm) clazz.newInstance();
			Field[] f_ar = clazz.getDeclaredFields();
			for(Field f : f_ar){
				f.setAccessible(true);
				f.set(form, req.getParameter(f.getName()));
				f.setAccessible(false);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		return form;
	}
}
